﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Activity.Consts
{
    public enum OauthType
    {
        /// <summary>
        /// 静默授权
        /// </summary>
        snsapi_base,
        /// <summary>
        /// 完整授权
        /// </summary>
        snsapi_userinfo
    }

    public class WeiXinConst
    {
        #region Value Const

        /// <summary>
        /// 微信开发者 AppId
        /// </summary>
        public const string AppId = "wx6d3a3a25e9576db6";


        /// <summary>
        /// 微信开发者 Secret
        /// </summary>
        public const string Secret = "3a444c2ec6dc28963fc6a20037a560cf";


        /// <summary>
        /// 用于验证 请求 是否来自 微信
        /// </summary>
        public const string Token = "km2016";
        #endregion

        #region AccessTokenUrl

        /// <summary>
        /// 公众号 获取Access_Token的Url(需Format  0.AppId 1.Secret)
        /// </summary>
        private const string AccessToken_Url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}";

        /// <summary>
        /// 公众号 获取Token的Url
        /// </summary>
        public static string WeiXin_AccessTokenUrl { get { return string.Format(AccessToken_Url, AppId, Secret); } }

        #endregion

        #region 获取用户信息Url

        /// <summary>
        /// 根据Code 获取用户OpenId Url
        /// </summary>
        public const string User_GetOpenIdUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code";

        /// <summary>
        /// 根据Code 获取用户OpenId的Url 需要Format 0.code
        /// </summary>
        public static string WeiXin_User_OpenIdUrl { get { return string.Format(User_GetOpenIdUrl, AppId, Secret, "{0}"); } }
        private const string refresh_token_url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={0}&grant_type=refresh_token&refresh_token={1}";
        public static string RefreshTokenUrl
        {
            get { return string.Format(refresh_token_url, AppId, "{0}"); }
        }
        /// <summary>
        /// 根据OpenId 获取用户基本信息 Url（需要Format0.access_token 1.openid）
        /// </summary>
        public const string WeiXin_User_GetInfoUrl = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN";

        public const string Weixin_User_Userinfo = "https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN";

        const string get_user_list = "https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}&next_openid={1}";
        //public static string GetUserListUrl(string NextOpenID = "")
        //{
        //    return string.Format(get_user_list, AccessToken.GetAccssTokenFromCacheServer(), NextOpenID);
        //}
        #endregion

        #region OAuth2授权Url


        /// <summary>
        /// OAuth2授权Url，需要Format0.AppId  1.Uri  2.state
        /// </summary>
        private const string OAuth2_Url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope={3}&state={2}#wechat_redirect";

        /// <summary>
        /// OAuth2授权Url，需要Format  0.Uri  1.state
        /// </summary>
		public static string WeiXin_User_OAuth2Url { get { return string.Format(OAuth2_Url, AppId, "{0}", "{1}", "{2}"); } }

        #endregion

        #region QrCode Url

        /// <summary>
        /// 创建获取QrCode的Ticket Url  需要Format 0 access_token
        /// </summary>
        public const string WeiXin_Ticket_CreateUrl = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}";

        /// <summary>
        /// 获取二维码图片Url,需要Format 0.ticket
        /// </summary>
        public const string WeiXin_QrCode_GetUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={0}";

        #endregion
    }
}